package main

import (
	"fmt"
	"gitee.com/lwow2025/snake-go/common/log"
	"go.uber.org/zap"
	"path/filepath"
	"os"
	"gitee.com/lwow2025/snake-go/common/util"
	"gitee.com/lwow2025/snake-go/config"
	"gitee.com/lwow2025/snake-go/common/shell_util"
	"gitee.com/lwow2025/snake-go/fk-snake"
)

func debugLog() {
	appDir := util.AppDataDir(config.AppName)
	os.MkdirAll(appDir, 0755)
	logPath := filepath.Join(appDir, config.DebugLogName)

	// set log output
	cfg := zap.NewDevelopmentConfig()
	cfg.OutputPaths = []string{ logPath }
	cfg.ErrorOutputPaths = []string{ logPath }
	log.InitLog(cfg)
	log.L.Info("log started")

	// open tem and show log
	tailCmd := fmt.Sprintf("tail -f %v", logPath)

	if !shell_util.Alive(tailCmd) {
		rb, err := shell_util.ExecCmdByTmpFile([]byte(shell_util.OpenTerminalExec(tailCmd)))
		if err != nil {
			panic(string(rb) + " err:" + err.Error())
		}
	}
}

func prodLog() {
	cfg := zap.NewProductionConfig()
	cfg.OutputPaths = []string{}
	cfg.ErrorOutputPaths = []string{}
	cfg.Level = zap.NewAtomicLevelAt(zap.FatalLevel)
	log.InitLog(cfg)
}

func main() {
	prodLog()
	//debugLog()

	app := fk_snake.NewSnakeGame(1)
	app.Start()
	app.Wait()
}
